home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 8 / Amoszine 8 (Disk 3 of 3).adf / Andy_Smith.lha / DirStruc.c < prev    next >
C/C++ Source or Header  |  1995-07-24  |  1KB  |  79 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dos/dos.h>
  4. #include <exec/exec.h>
  5. #include <clib/dos_protos.h>
  6. #include <clib/exec_protos.h>
  7.  
  8. BOOL ScanDisk(char *directory);
  9.  
  10. FILE *fopen(), *out_file;
  11.  
  12. void main(int argc, char *argv[])
  13. {
  14.     char search_dir[64];
  15.     char outputfile[64];
  16.  
  17.     printf("Directory Scanner - Thrown together by Andy Smith\n");
  18.     printf("A nice hack for Steve Bye\n\n");
  19.  
  20.     if (argc != 3)
  21.     {
  22.         printf("Excuse me pal, I am missing some arguments\n");
  23.         printf("USAGE: dirstruc <directory> <output file>\n\n");
  24.         return;
  25.     }
  26.  
  27.     strcpy(search_dir, *++argv);
  28.     strcpy(outputfile, *++argv);
  29.  
  30.     out_file = fopen(outputfile,"w");
  31.     
  32.     printf("Scanning directory %s.......\n",search_dir);
  33.     
  34.     if (!(ScanDisk(search_dir)))
  35.         printf("Whoops! Sommats gone wrong\n\n");
  36.  
  37.     printf("Scanning complete, writing to file %s\n",outputfile);
  38.     return;
  39. }
  40.  
  41. BOOL ScanDisk(char *directory)
  42. {
  43.     #ifdef _DCC
  44.         __aligned struct FileInfoBlock fib;
  45.     #else
  46.         struct FileInfoBlock __aligned fib;
  47.     #endif
  48.  
  49.     BPTR lock;
  50.     char full_path[255];
  51.  
  52.     if (!(lock = Lock(directory, ACCESS_READ))) return FALSE;
  53.     if (!(Examine(lock, &fib))) return FALSE;
  54.  
  55.     while (ExNext(lock, &fib))
  56.     {
  57.         strcpy(full_path, directory);
  58.         AddPart(full_path, fib.fib_FileName, 255);
  59.  
  60.         if (fib.fib_DirEntryType > 0)
  61.         {
  62.             if (!(ScanDisk(full_path)))
  63.             {
  64.                 UnLock(lock);
  65.                 return FALSE;
  66.             }
  67.         }
  68.         else
  69.         {
  70.             /* Save the filename to a data file */
  71.             strcat(full_path,"\n");
  72.             fputs(full_path, out_file);
  73.         }
  74.     }
  75.     UnLock(lock);
  76.     return TRUE;
  77. }
  78.  
  79.